import 'package:get/get.dart';
import 'package:mtf/app/base/BaseController.dart';
import 'package:mtf/app/data/UsdRecordEntity.dart';
import 'package:mtf/app/net/HttpManger.dart';
import 'package:mtf/app/routes/app_pages.dart';
import 'package:mtf/app/utils/AppUtils.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../utils/cache/AppCahche.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class propertyController extends BaseController with StateMixin{
  RxList<ListUSDElement> usdList=<ListUSDElement>[].obs;
  var account="".obs;
  var isShow=true.obs;
  var Profit_sum="".obs;
  var Storage_sum="".obs;

  RefreshController refreshController = RefreshController(initialRefresh: false);


  @override
  void onInit() {
    super.onInit();
    change(null, status: RxStatus.loading());
    refreshData();
  }

  void clickRecharge(){
    AppUtils.authAndMt5Check((){
      Get.toNamed(Routes.RECHARGE);
    });

  }

  void clickWithdrawal(){
    AppUtils.authAndMt5Check((){
      Get.toNamed(Routes.WITHDRAWAL);
    });
  }

  void clickCover(){
    AppUtils.authAndMt5Check((){
      Get.toNamed(Routes.COVER);
    });
  }

  void clickBankManager(){
    AppUtils.authAndMt5Check((){
      Get.toNamed(Routes.BANK_MANAGER);
    });
  }

  void clickWithdrawRecord(){
    AppUtils.authAndMt5Check((){
      Get.toNamed(Routes.WITHDRAW_RECORD);
    });
  }
  
  void clickRechargeRecord(){
    AppUtils.authAndMt5Check((){
      Get.toNamed(Routes.RECHARGE_RECORD);
    });
  }

  void clickUsd(){
    AppUtils.authAndMt5Check((){
      Get.toNamed(Routes.USD_RECORD);
    });
  }

  void reqUsdRecord() async{
    var resp=await HttpManager.reqUsdRecord(1);
    if(resp.isSuccessData()){
      usdList.assignAll(resp.data!.list);
    }

  }

  void refreshData() async{
    reqUsdRecord();
    showLoading();
    var resp=await HttpManager.reqUserInfo();
    if(resp.isSuccessData()){
      account.value=resp.data!.mt5Balance ??"";
    }
    if(AppCache.getUserInfo().mt5Login!=null){
      var respIncome=await HttpManager.reqIncome();
      if(respIncome.isSuccessData()){
        Profit_sum.value=respIncome.data!.profitSum.toString();
        Storage_sum.value=respIncome.data!.storageSum.toString();
      }
    }

    hideLoading();
    refreshController.refreshCompleted();
    change(null, status: RxStatus.success());
  }

}
